import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: () => import("../views/Home.vue"),
    children: [
      {
        path: "/home",
        redirect: "/home/recommend",
      },
      {
        // 路由重定向
        path: "/home/recommend",
        component: () => import("../views/home/Recommend.vue"),
        children: [
          {
            // 路由重定向
            path: "/home/recommend",
            redirect: "/home/recommend/recommend",
          },
          {
            // 三级路由-推荐
            path: "/home/recommend/recommend",
            component: () => import("../views/home/recommend/index.vue"),
          },
          {
            // 三级路由-视频
            path: "/home/recommend/video",
            component: () => import("../views/home/video/index.vue"),
          },
          {
            // 三级路由-即将上线
            path: "/home/recommend/beComingSoon",
            component: () => import("../views/home/becomingsoon/index.vue"),
          },
          {
            // 三级路由-排行榜
            path: "/home/recommend/ranking",
            component: () => import("../views/home/ranking/index.vue"),
          },
        ],
      },
      {
        path: "/home/discover",
        component: () => import("../views/home/Discover.vue"),
      },
      {
        path: "/home/dynamic",
        component: () => import("../views/home/Dynamic.vue"),
        children: [
          {
            path: "/home/dynamic",
            redirect: "/home/dynamic/recommend",
          },
          // 动态推荐页
          {
            path: "/home/dynamic/recommend",
            component: () => import("../views/home/dynamic/Dy-recommend.vue"),
          },
          // 动态关注页
          {
            path: "/home/dynamic/attention",
            component: () => import("../views/home/dynamic/Dy-attention.vue"),
          },
          // 动态论坛页
          {
            path: "/home/dynamic/forum",
            component: () => import("../views/home/dynamic/Dy-forum.vue"),
          },
        ],
      },
      {
        path: "/home/message",
        component: () => import("../views/home/Message.vue"),
        beforeEnter: (to, from, next) => {
          // reject the navigation
          if (localStorage.getItem("loginstate")) {
            next();
          } else {
            next("/login");
          }
        },
      },
      {
        path: "/home/game",
        component: () => import("../views/home/Game.vue"),
      },
    ],
  },
  {
    path: "/details/:id",
    component: () => import("../views/Details.vue"),
  },
  {
    path: "/login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/search",
    component: () => import("../views/Search.vue"),
  },
  {
    path: "/:pathMatch(.*)*",
    name: "NotFound",
    component: () => import("../views/NotFound.vue"),
  },
  // 动态
  {
    path: "/condition",
    component: () => import("../views/popup/Condition.vue"),
  },
  // 关注
  {
    path: "/guanzhu",
    component: () => import("../views/popup/Guanzhu.vue"),
  },
  // 好友
  {
    path: "/haoyou",
    component: () => import("../views/popup/Haoyou.vue"),
  },
  // 收藏
  {
    path: "/shoucang",
    component: () => import("../views/popup/Shoucang.vue"),
  },
  // 订单
  {
    path: "/dingdan",
    component: () => import("../views/popup/Dingdan.vue"),
  },
  // 浏览历史
  {
    path: "/lishi",
    component: () => import("../views/popup/Lishi.vue"),
  },
  // TAPTAO周边
  {
    path: "/zhoubian",
    component: () => import("../views/popup/Zhoubian.vue"),
  },
  // 兑换中心
  {
    path: "/duihuan",
    component: () => import("../views/popup/Duihuan.vue"),
  },
  // 建议和反馈
  {
    path: "/jianyi",
    component: () => import("../views/popup/Jianyi.vue"),
  },
  // 设置
  {
    path: "/shezhi",
    component: () => import("../views/popup/Shezhi.vue"),
  },
  // 夜间模式
  {
    path: "/moshi",
    component: () => import("../views/popup/Moshi.vue"),
  },
  // 当前版本
  {
    path: "/banben",
    component: () => import("../views/popup/Banben.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

export default router;
